﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace PaperWorld.IRepository
{
    /// <summary>
    /// 仓储模式泛型基接口
    /// </summary>
    /// <typeparam name="T">T 是一个领域模型对象</typeparam>
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 查询仓储，返回T的集合
        /// </summary>
        /// <returns>T的集合</returns>
        IEnumerable<T> FindAll();

        /// <summary>
        /// 查询仓储，返回分页并排序后的T的集合
        /// </summary>
        /// <typeparam name="TOrderKey">作为排序的属性类型</typeparam>
        /// <param name="filter">筛选的lambda表达式对象</param>
        /// <param name="orderBy">排序的lambda表达式对象</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="recordsCount">记录总数，传出参数</param>
        /// <returns>T的集合</returns>
        IEnumerable<T> FindAllByPage<TOrderKey>(Expression<Func<T, bool>> filter, Expression<Func<T, TOrderKey>> orderBy, int pageSize, int pageIndex, out int recordsCount);


        /// <summary>
        /// 获取模型
        /// </summary>
        /// <param name="predicate">筛选的lambda表达式对象</param>
        /// <returns>T的实例</returns>
        T GetModel(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 更新模型，并返回更新后模型的实例
        /// </summary>
        /// <param name="model">更新的模型</param>
        /// <returns>更新后模型的实例</returns>
        T UpdateModel(T entity);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        int DeleteModel(Expression<Func<T, bool>> predicate);
    }
}
